package com.woniuxy.processweb.controller;


import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.MyJwtUtil;
import com.woniuxy.processdao.model.Pricard;
import com.woniuxy.processmodel.dto.PriCardDto;
import com.woniuxy.processmodel.form.UpdatePricardForm;
import com.woniuxy.processservice.service.PricardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 私教课流程表 前端控制器
 * </p>
 *
 * @author 冉杰
 * @since 2024-01-15
 */
@RestController
@RequestMapping("/pricard")
@Api(tags = {"私教课进度记录接口"})
public class PricardController {
    @Autowired
    private PricardService pricardService;

    @ApiOperation("新增私教课进度接口")//私教课订单生成时调用该接口
    @GetMapping("/add")
    public Result addPricard(String orderNum){
        pricardService.addValidCardStep(orderNum);
        return Result.success("新增私教课进度成功");
    }
    @ApiOperation("修改私教课进度接口")//每完成一节私教课后，教练端调用此接口进行进度的记录
    @PostMapping("/update.coach")
    public Result updatePricard(@RequestBody UpdatePricardForm form, @RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        pricardService.updatePricard(form,coachId);
        return Result.success("修改私教课进度成功");
    }

    @ApiOperation("根据id查询私教课进度接口")
    @GetMapping("/look")
    public Result lookPricard(Integer pricardId){
        Pricard pricard = pricardService.lookPricard(pricardId);
        return Result.success("新增有效期卡进度成功",pricard);
    }

    @ApiOperation("用户查询自己的私教课进度接口")
    @GetMapping("/userLook")
    public Result userLookPricard(String orderNum,@RequestHeader String token){
        Integer userId = MyJwtUtil.getUserIdByKey(token, "userId");
        List<PriCardDto> dtos = pricardService.userLookPricard(orderNum,userId);
        return Result.success("用户查询私教课进度成功",dtos);
    }
    @ApiOperation("教练查询私教课进度接口")
    @GetMapping("/coachLook.coach")
    public Result coachLookPricard(String orderNum,@RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        List<PriCardDto> dtos = pricardService.coachLookPricard(orderNum,coachId);
        return Result.success("用户查询私教课进度成功",dtos);
    }

    


}

